package com.example.demo.设计模式.代理模式.动态代理.CGLIB代理;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @description:
 * @projectName:demo
 * @see:设计模式.代理模式.动态代理.CGLIB代理
 * @author:袁成龙
 * @createTime:2020/10/13 7:53
 * @version:1.0
 */
public class TestInterfaceIMpl<T> implements MethodInterceptor {


    public Enhancer enhancer = new Enhancer();

    public T getObject(Class<T> tClass){
        enhancer.setSuperclass(tClass);
        enhancer.setCallback(this);

        return (T)enhancer.create();
    }



    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("========通过接口动态实现操作========");

        return "1111111";
    }
}